<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/laydate/laydate.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
    <script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<div id="formArea">
	<table class="table-top">
		<tr>
			<td>
				<label class="label">调拨日期</label>
			</td>
			<td>
				<input type="text" n="date" class="input search-date" name="dateStart" autocomplete="off"/>&nbsp;-&nbsp;
				<input type="text" n="date" class="input search-date" name="dateEnd" autocomplete="off"/>
			</td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
				<button class="button" id="create"><span>新增</span></button>
			</td>
		</tr>
	</table>
</div>

</fieldset>
<div id="table"></div>

<script>
    var nowDate = app.time2str(new Date()),startDate = new Date(nowDate.substr(0,8)+'01');

    var dateStart = laydate.render({
        elem: 'input[name="dateStart"]',value:nowDate.substr(0,8)+'01',max:nowDate,
        done: function(value,date){
            if(value){
                date.month=date.month-1;
                dateEnd.config.min = date;
            }else{
                dateEnd.config.min=dateStart.config.min;
            }
        }
    });
    var dateEnd = laydate.render({
        elem: 'input[name="dateEnd"]',value:nowDate,min:nowDate.substr(0,8)+'01',
        done: function(value,date){
            if(value){
                date.month=date.month-1;
                dateStart.config.max = date;
            }else{
                dateStart.config.max=dateEnd.config.max;
            }
        }
    });

    $(function(){
        $('#create').click(function(){
            location.href = 'transfer_add.html';
        });

        $('#query').click(function(){
            $('#table').datagrid("reload",app.serializeForm());
        });

        var currDate = app.time2str(new Date().getTime());
        var firstDate = currDate.substr(0,8)+'01';

        laydate.render({elem: '#date',range: '~',value:firstDate+' ~ '+currDate});

        $('#table').datagrid({
            url:app.BASE_API_URL+'transfer/page',
            queryParams:{dateStart:startDate.getTime(),dateEnd:new Date().getTime()},
            columns:[
                {field:'date',title:'调拨日期',width:100,formatter:app.timeFormatter},
                {field:'code',title:'调拨编号',width:180,formatter:function (row) {
                        return '<a class="a" href="./transfer_add.html?id='+row.id+'">DB'+row.code+'</a>';
                    }},
                {field:'outStoreName',title:'调出仓库',width:120},
                {field:'inStoreName',title:'调入仓库',width:120},
                {field:'number',title:'调拨总数',width:100,n:'number'},
                {field:'userName',title:'制单人',width:100},
                {field:'status',title:'单据状态',width:100,formatter:function (row) {
                        if( row.status == '1' ){
                            return app.getLable('未调拨','warning');
                        }else if( row.status == '2' ){
                            return app.getLable('已调拨','success');
                        }else{
                            return '状态异常';
						}
                    }}
            ]
        });
    });

    function loadDataSuccess(){
        $('.a[dg="1"]').click(function(){
            var row = $(this).parent().parent().data();
            location.href = "transfer_add.html?code="+row.code+"&id="+row.id+"&status="+row.status;
        });
    }
</script>

</body>
</html>